package com.vx.vxbug.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vx.vxbug.dao.ICommentDao;
import com.vx.vxbug.entities.Comment;

@Service
public class CommentService {

	@Autowired
	private ICommentDao CommentDao;

    @Autowired
    private SendMailService sm;

    @Autowired
    private UserService uS;

    @Autowired
    private BugService bS;

    @Autowired
    private ProgramService pS;

	public void addComment(Comment b) {
		CommentDao.addComment(b);
        String to = uS.getUserById(pS.getProgramById(bS.getBugById(b.getBugId()).getProgramId()).getCreatorUserId()).getEmail();
        sm.sendEmail(to, "Someone has commented on bug " + bS.getBugById(b.getBugId()).getBugTitle() +"!", "You can check it out at\nhttp://quarcum.dyndns.org:8087/vxBug/program/" + bS.getBugById(b.getBugId()).getProgramId() + "/bug/" + b.getBugId());
	}

	public Comment getCommentById(int id) {
		return CommentDao.getCommentById(id);
	}

	public List<Comment> getAllCommentsForBugId(int id) {
		return CommentDao.getAllCommentsForBugId(id);
	}

}
